package com.example.ctl;

import com.example.event.ProductChangedEvent;
import com.example.prop.EventDispatcher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @dec:
 * @author： ysf
 * @createDate: 2021/5/11 9:22
 **/
@RestController
@RequestMapping("/api")
public class Test {

    @Autowired
    private EventDispatcher eventDispatcher;

    @RequestMapping("/event")
    void send() {
//        System.out.println("同步事件处理业务逻辑start" + "ThreadName:" + Thread.currentThread().getName());
//        eventDispatcher.post(new ProductChangedEvent(11L));
//        System.out.println("同步事件处理业务逻辑end" + "ThreadName:" + Thread.currentThread().getName());
        System.out.println("异步事件处理业务逻辑start" + "ThreadName:" + Thread.currentThread().getName());
        eventDispatcher.postAsync(new ProductChangedEvent(22L));
        System.out.println("异步事件处理业务逻辑end" + "ThreadName:" + Thread.currentThread().getName());
    }

    ;

}
